#include<vector>
#include<string>
#include<unordered_map>
#include<algorithm>
using namespace std;

class Solution {
public:
    vector<string> printKMoves(int K) {
        int x = 0, y = 0;
        unordered_map<string, bool> hashMap;
        vector<vector<int>>actions = { {0,1},{1,0},{0,-1},{-1,0} };
        int direct = 0;
        vector<int>boundary(4);  //left,top,right,bottom
        for (int i = 0; i < K; ++i) {
            bool white = true;
            auto key = to_string(x) + " " + to_string(y);
            if (hashMap.find(key) != hashMap.end())
                white = hashMap[key];
            hashMap[key] = !white;
            if (white)
                direct = (direct + 1) % 4;
            else
                direct = (direct + 3) % 4;
            x += actions[direct][0];
            y += actions[direct][1];
            boundary[0] = min(boundary[0], y);
            boundary[1] = min(boundary[1], x);
            boundary[2] = max(boundary[2], y);
            boundary[3] = max(boundary[3], x);
        }
        vector<string>matrix(boundary[3] - boundary[1] + 1, string(boundary[2] - boundary[0] + 1,'_'));
        for (auto& kv : hashMap) {
            if (!kv.second) {
                auto& key = kv.first;
                int index=key.find_first_of(' ');
                int i = atoi(key.substr(0, index).c_str());
                int j = atoi(key.substr(index + 1, key.length() - index - 1).c_str());
                matrix[i - boundary[1]][j - boundary[0]] = 'X';
            }
        }
        static vector<char> vec = { 'R','D','L','U' };
        matrix[x - boundary[1]][y - boundary[0]] = vec[direct];
        return matrix;
    }
};

int main() {
    Solution sol;
    sol.printKMoves(100000);
}